import { type NitroFetchRequest } from 'nitropack'
import { onRequest, onResponse, onResponseError } from '@/service/apiFetch'

function useClientApi<T = unknown, R extends NitroFetchRequest = NitroFetchRequest>(
  request: Parameters<typeof $fetch<T, R>>[0],
  options?: Partial<Parameters<typeof $fetch<T, R>>[1]>,
) {
  const opts = {
    ...options,
  }
  return $fetch<T, R>(request, {
    ...opts,
    onRequest,
    onResponse,
    onResponseError,
  })
}

export default useClientApi
